#include "RoomSystem.h"
#include <Game/World/Components/Room.h>
#include <Game/EntityManager.h>
#include <Game/Entity.h>

using namespace Game;
using namespace World;
using namespace Systems;
using namespace Totem;

RoomSystem::RoomSystem(GameManager &gameMgr)
	: gameMgr(gameMgr), entityMgr(NULL)
{
	entityMgr = new EntityManager();
	Components::Room::RegisterToFactory(entityMgr->getFactory());
}

RoomSystem::~RoomSystem()
{
	if(entityMgr)
		delete entityMgr;
}

Entity &RoomSystem::createRoom()
{
	Entity &room = entityMgr->create();
	room.addComponent<RoomSystem>("Room", *this);
	return room;
}

void RoomSystem::add(Components::Room *room)
{
	rooms.push_back(room);
}

void RoomSystem::remove(Components::Room *room)
{
	for(U32 i = 0; i < rooms.size(); i++)
	{
		if(rooms[i] == room)
		{
			rooms[i] = rooms.back();
			rooms.pop_back();
			break;
		}
	}
}

void RoomSystem::update(float dt)
{
	entityMgr->update(dt);
}
